/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package arimaa;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

/**
 *
 * @author student
 */
public class Board extends JPanel {

    Square[][] boardSquares = new Square[8][8];
    BufferedImage bg;

    Board(Square[][] boardSquares) {
        this.boardSquares = boardSquares;
        try {
            bg = ImageIO.read(new File("./images/BoardStoneBig.jpg"));
        } catch (Exception e) {
            System.out.println("Error loading File");
            e.printStackTrace();
        }
        setBackground(Color.red);
    }

    public void updateSquares(Square[][] boardSquares) {
        this.boardSquares = boardSquares;
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(bg, 0, 0, this.getWidth(), this.getHeight(), this);
        for (int i = 0; i < boardSquares.length; i++) {
            for (int j = 0; j < boardSquares.length; j++) {
                Piece current = boardSquares[i][j].getPiece();
                //drawing the piece contained within each square on the board
                if(current != null) {
                    current.paintSelf(g, i*getWidth()/8, j*getHeight()/8, getWidth()/8, getHeight()/8);
                }

            }

        }
    }
}
